package com.mes.schedule.domain;

import java.io.Serializable;
import java.util.List;

import com.mes.common.util.IdentityGenerator;
import com.mes.schedule.manager.PreAssignResult;
/**
 * 任务分派
 * @author Administrator
 * @version 1.0
 * @created lqm-2011 14:55:23
 */
public class TaskAssignScheme  implements Comparable  , Serializable {
	//本次预分配的工序任务
	protected SOperationTask operationTask;
	//本次预分配任务所属的组，便于多线程同步，组内比较
	protected List<TaskAssignScheme> alterResourceList;

	protected String preAssnUid;
	protected Resource resource;
	protected float priority;
	protected int needCapability;
	
	protected double setupTime;
	protected double runTime;
	protected long costPerUnit;
	protected long costPerUnitOvertime;

	protected Float score;
//	protected PreAssignResult  preAssignResult;
	
	protected SDevice mainDevice;

//	public SDevice getMainDevice(){
//		Resource currentResource=this.resource;
//		if (currentResource instanceof CombinedResource)
//			currentResource = ((CombinedResource) currentResource)
//					.getMainResource();//取得主资源
//		return  (SDevice)currentResource;
//	}	
	

	public Float getScore() {
		return score;
	}
	public void setScore(Float score) {
		this.score = score;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((preAssnUid == null) ? 0 : preAssnUid.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final TaskAssignScheme other = (TaskAssignScheme) obj;
		if (preAssnUid == null) {
			if (other.preAssnUid != null)
				return false;
		} else if (!preAssnUid.equals(other.preAssnUid))
			return false;
		return true;
	}


	/**
	 * @return the priority
	 */
	public float getPriority() {
		return priority;
	}
	/**
	 * @param priority the priority to set
	 */
	public void setPriority(float priority) {
		this.priority = priority;
	}
	/**
	 * @return the needCapability
	 */
	public int getNeedCapability() {
		return needCapability;
	}
	/**
	 * @param needCapability the needCapability to set
	 */
	public void setNeedCapability(int needCapability) {
		this.needCapability = needCapability;
	}
	/**
	 * @return the setupTime
	 */
	public double getSetupTime() {
		return setupTime;
	}
	/**
	 * @param setupTime the setupTime to set
	 */
	public void setSetupTime(double setupTime) {
		this.setupTime = setupTime;
	}
	/**
	 * @return the runTime
	 */
	public double getRunTime() {
		return runTime;
	}
	/**
	 * @param runTime the runTime to set
	 */
	public void setRunTime(double runTime) {
		this.runTime = runTime;
	}
	/**
	 * @return the costPerUnit
	 */
	public long getCostPerUnit() {
		return costPerUnit;
	}
	/**
	 * @param costPerUnit the costPerUnit to set
	 */
	public void setCostPerUnit(long costPerUnit) {
		this.costPerUnit = costPerUnit;
	}
	/**
	 * @return the costPerUnitOvertime
	 */
	public long getCostPerUnitOvertime() {
		return costPerUnitOvertime;
	}
	/**
	 * @param costPerUnitOvertime the costPerUnitOvertime to set
	 */
	public void setCostPerUnitOvertime(long costPerUnitOvertime) {
		this.costPerUnitOvertime = costPerUnitOvertime;
	}
	public Resource getResource() {
		return resource;
	}
	public void setResource(Resource resource) {
		this.resource = resource;
	}


//	public PreAssignResult getPreAssignResult() {
//		return preAssignResult;
//	}
//	public void setPreAssignResult(PreAssignResult preAssignResult) {
//		this.preAssignResult = preAssignResult;
//	}


	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		TaskAssignScheme ta=(TaskAssignScheme)o;
		return this.score.compareTo(ta.getScore());

	}
	public TaskAssignScheme(SOperationTask operationTask) {
		super();
		this.operationTask=operationTask;
		//产生一个预分配唯一号
		this.preAssnUid = IdentityGenerator.GetIdentityUUID();
	}



	public TaskAssignScheme(SOperationTask operationTask,Resource resource) {
		super();
		this.operationTask=operationTask;
		this.resource=resource;
		//产生一个预分配唯一号
		this.preAssnUid = IdentityGenerator.GetIdentityUUID();
	}


	public SOperationTask getOperationTask() {
		return operationTask;
	}


	public void setOperationTask(SOperationTask operationTask) {
		this.operationTask = operationTask;
	}


	public List<TaskAssignScheme> getAlterResourceList() {
		return alterResourceList;
	}


	public void setAlterResourceList(List<TaskAssignScheme> alterResourceList) {
		this.alterResourceList = alterResourceList;
	}





	public String getPreAssnUid() {
		return preAssnUid;
	}


	public void setPreAssnUid(String preAssnUid) {
		this.preAssnUid = preAssnUid;
	}
	public SDevice getMainDevice() {
		
		if(this.mainDevice!=null)
			return mainDevice;
		
		Resource currentResource=this.resource;
		if (currentResource instanceof CombinedResource)
			currentResource = ((CombinedResource) currentResource)
					.getMainResource();//取得主资源
		return  (SDevice)currentResource;
		
	}
	public void setMainDevice(SDevice mainDevice) {

		
		this.mainDevice = mainDevice;
	}





	/**
	 * @author lcs
	 * @see here is use for AssignManager
	 */
	protected PreAssignResult  preAssignResult;

	public PreAssignResult getPreAssignResult() {
		return preAssignResult;
	}
	public void setPreAssignResult(PreAssignResult preAssignResult) {
		this.preAssignResult = preAssignResult;
	}
	

}